package com.wgh.api.client.fallback;

import com.wgh.api.client.inventory.InventoryClient;
import com.wgh.inventory.dto.InventoryDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 库存服务客户端熔断降级实现
 */
@Component
@Slf4j
public class InventoryClientFallback implements InventoryClient {

    @Override
    public InventoryDTO getInventoryByProductId(Long productId) {
        log.error("库存服务调用失败，降级处理：getInventoryByProductId(productId={})", productId);
        return null;
    }

    @Override
    public List<InventoryDTO> getInventoryListByProductIds(List<Long> productIds) {
        log.error("库存服务调用失败，降级处理：getInventoryListByProductIds(productIds={})", productIds);
        return new ArrayList<>();
    }

    @Override
    public Boolean deductInventory(Map<Long, Integer> inventoryMap) {
        log.error("库存服务调用失败，降级处理：deductInventory(inventoryMap={})", inventoryMap);
        return false;
    }

    @Override
    public Boolean increaseInventory(Map<Long, Integer> inventoryMap) {
        log.error("库存服务调用失败，降级处理：increaseInventory(inventoryMap={})", inventoryMap);
        return false;
    }

    @Override
    public Map<Long, Boolean> checkInventoryStatus(List<Long> productIds, List<Integer> quantities) {
        log.error("库存服务调用失败，降级处理：checkInventoryStatus(productIds={}, quantities={})", productIds, quantities);
        Map<Long, Boolean> result = new HashMap<>();
        // 默认返回无库存
        for (Long productId : productIds) {
            result.put(productId, false);
        }
        return result;
    }
}